package com.dangdang.nono.service;

import javax.annotation.Resource;

import com.dangdang.nono.entity.Order;
import com.dangdang.nono.repository.OrderRepository;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Order 服务对象.
 * 
 * @author gaohongtao
 */
@Service
@Transactional
public class OrderService {
    
    @Resource
    private OrderRepository orderRepository;
    
    @Transactional(readOnly = true)
    public void select() {
        System.out.println(orderRepository.selectAll());
    }
    
    public void clear() {
        orderRepository.deleteAll();
    }
    
    public void fooService() {
        Order criteria = new Order();
        for(int i=0;i<1000;i++) {
            criteria.setUserId(i);
            criteria.setStatus("INSERT");
            orderRepository.insert(criteria);
        }
    }
    
    public void fooServiceWithFailure() {
        fooService();
        throw new IllegalArgumentException("failed");
    }
}
